﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TCHSHue.Modules.IndexControl.Slider
{
    public partial class ctrImageSlider : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CreateSlideImage();
            }
        }
        private void CreateSlideImage()
        {
            //Lấy danh sách các file ảnh để làm slide image
            DirectoryInfo diFiles = new DirectoryInfo(Server.MapPath("~/Upload/SlideImage"));
            var listFile = diFiles.GetFiles("*.*");
            if (listFile == null || listFile.Count() == 0)
            {
                return;
            }
            List<ImageSlide> list = new List<ImageSlide>();
            foreach (var fileImage in listFile)
            {
                if (fileImage.Extension == ".png" || fileImage.Extension == ".jpg" || fileImage.Extension == ".gif")
                                      list.Add(new ImageSlide(){ImageUrl = "../../Upload/SlideImage/" + fileImage.Name});
            }
            rptQuangCao.DataSource = list;
            rptQuangCao.DataBind();
        }
    }
    class ImageSlide
    {
        public string ImageUrl { get; set; }
    }
}